import { useAuthStore } from '@/store/modules/auth'

export default function(to, from, next) {
  const authStore = useAuthStore()
  
  // 检查是否需要认证
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!authStore.isAuthenticated) {
      next({ name: 'Login' })
    } else {
      next()
    }
  } else {
    // 不需要认证的路由直接通过
    next()
  }
}